package com.siwei.mes.entity.experiment.concrete.batch;

import com.alibaba.fastjson.JSONObject;
import com.siwei.mes.common.util.JsonUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import org.apache.commons.lang.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 抗压强度
 *
 * @Description: 抗压强度  CONCRETE_PARAM_KYQD
 * @Version: 1.0
 * @author: chenmaolin
 * @date: 2023/12/21 22:29
 */
@Data
public class ConcreteKyqd {
    @ApiModelProperty(value = "7天单项结论")
    private String dxjl7d = "";
    @ApiModelProperty(value = "28天单项结论")
    private String dxjl28d = "";
    @ApiModelProperty(value = "检测日期")
    private String jcrq = "";

    @ApiModelProperty(value = "试件尺寸")
    private String sjcc = "";

    @ApiModelProperty(value = "强度7天")
    private List<QdInfo> qd7d = this.generateQdInfo(3);

    @ApiModelProperty(value = "7天平均值")
    private String pjz7d = "";

    @ApiModelProperty(value = "7天折算系数")
    private String zsxs7d = "";

    @ApiModelProperty(value = "7天富余系数")
    private String fyxs7d = "";

    @ApiModelProperty(value = "7天折算标准强度")
    private String zsbzqd7d = "";

    @ApiModelProperty(value = "龄期")
    private String lq = "";

    @ApiModelProperty(value = "强度28天")
    private List<QdInfo> qd28d = this.generateQdInfo(3);

    @ApiModelProperty(value = "28天平均值")
    private String pjz28d = "";

    @ApiModelProperty(value = "28天折算系数")
    private String zsxs28d = "";

    @ApiModelProperty(value = "28天富余系数")
    private String fyxs28d = "";

    @ApiModelProperty(value = "28天折算标准强度")
    private String zsbzqd28d = "";


    @Data
    @Accessors(chain = true)
    @ApiModel("强度信息")
    public static class QdInfo {
        @ApiModelProperty(value = "下标")
        private String index = "";

        @ApiModelProperty(value = "荷载")
        private String hz = "";

        @ApiModelProperty(value = "强度")
        private String qd = "";
    }

    /**
     * 生成固定的强度
     *
     * @param i 生成个数
     * @return
     */
    private List<QdInfo> generateQdInfo(int i) {
        List<QdInfo> list = new ArrayList<>();
        for (int j = 0; j < i; j++) {
            int index = i + 1;
            QdInfo qdInfo = new QdInfo().setIndex(index + "").setHz("").setQd("");
            list.add(qdInfo);
        }
        return list;
    }


    /**
     * 字符串转成对象 然后再转成json
     *
     * @param object
     * @return
     */
    public static JSONObject toJsonObject(Object object) {
        ConcreteKyqd entity = new ConcreteKyqd();
        if (object == null) {
            return JsonUtils.beanToObject(entity);
        }
        if (object instanceof String) {
            entity = JsonUtils.getObject((String) object, ConcreteKyqd.class);
        } else if (object instanceof JSONObject) {
            entity = JsonUtils.getObject((JSONObject) object, ConcreteKyqd.class);
        }
        return JsonUtils.beanToObject(entity);
    }

    /**
     * 校验必检的
     *
     * @param objJson
     * @return
     */
    public static String checkIsMust(JSONObject objJson, String name) {
        if (objJson.isEmpty()) {
            return null;
        }
        ConcreteKyqd entity = JsonUtils.getObject(objJson, ConcreteKyqd.class);
        List<QdInfo> qd7d = entity.getQd7d();
        for (QdInfo qdInfo : qd7d) {
            String qd = qdInfo.getQd();
            if (StringUtils.isBlank(qd) || "0".equals(qd) || "null".equals(qd)) {
                return "存在必检项(" + name + ")未检测，请先检测！";
            }
        }
        List<QdInfo> qd28d = entity.getQd28d();
        for (QdInfo qdInfo : qd28d) {
            String qd = qdInfo.getQd();
            if (StringUtils.isBlank(qd) || "0".equals(qd) || "null".equals(qd)) {
                return "存在必检项(" + name + ")未检测，请先检测！";
            }
        }
        return null;
    }
}
